package 笔试.同城58;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @author:谢君臣
 * @Date:2021/8/10-14:30
 * @version:1.0
 * @function:
 */
public class 链表合并 {
    public static void main(String[] args) {
        Queue queue = new ArrayDeque();
    }
    public ListNode test(ListNode headA,ListNode headB){
        if (headA==null||headB==null)
            return headA==null?headB:headA;
        ListNode temp;
        temp = headA;
        if (headA.val>headB.val){
            headA = headB;
            headB = temp;
        }
        temp = headA;
        while (temp.next!=null&&headB!=null){
            if (temp.next.val>headB.val){
                ListNode node = new ListNode(headB.val,null);
                headB = headB.next;
                Insert(temp,node);
            }
            temp = temp.next;
        }
        if (headB!=null) temp.next = headB;
        return headA;
    }

    private void Insert(ListNode root, ListNode node) {
      node.next = root.next;
      root.next = node;
    }
}
class ListNode{
    int val;
    ListNode next;

    public ListNode() {
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}


